package rudy.elevator.ui;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.print.attribute.standard.JobName;
import javax.swing.*;

public class MainFrame extends JFrame {
   // JPanel contentPane;
    Container contentPane;
    BorderLayout borderLayout1 = new BorderLayout();

    public MainFrame() {
        try {
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            jbInit();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    /**
     * Component initialization.
     *
     * @throws java.lang.Exception
     */
    private JTextField maxField;
    private JTextField minField;
    private MainPanel  panel;
    private void jbInit() throws Exception {
        contentPane =  getContentPane();
        contentPane.setLayout(borderLayout1);
        panel = new MainPanel(2,17);
        //TestPanel  panel = new TestPanel();
        contentPane.add(panel,BorderLayout.CENTER);
        JPanel settingPanel=new JPanel();
        settingPanel.setBackground(new Color(100,150,1));
        JLabel minLabel=new JLabel("Min:");
         minField=new JTextField(5);
        settingPanel.add(minLabel);
        settingPanel.add(minField);
        
        JLabel maxLabel=new JLabel("Max:");
         maxField=new JTextField(5);
        settingPanel.add(maxLabel);
        settingPanel.add(maxField);
        
 
        JButton updateBtn=new JButton("Update");
        updateBtn.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				int min=0;
				int max=0;
				try{
				min=Integer.parseInt(minField.getText());
				max=Integer.parseInt(maxField.getText());
				}catch (Exception e) {
					
				}
				if (min<max) {
					contentPane.remove(panel);
					panel=new MainPanel(min, max+1);
					contentPane.add(panel,BorderLayout.CENTER);
					contentPane.repaint();
					contentPane.layout();
				}
			}
		});
        settingPanel.add(updateBtn);
        
        contentPane.add(settingPanel,BorderLayout.NORTH);
        
        setSize(new Dimension(600, 800));
        setTitle("Flit Emulator");
    }
}
